<template>
    <div class='view-container'>
    <ion-row class="app-layoutpanel">
        <ion-col v-show="detailsModel.container1.visible"  :size="12" style="" class="app-layoutpanel-container mob_list_card">
            <ion-row style="height:100%;">
                
                <ion-col v-show="detailsModel.rawitem1.visible"  :lg="3" :size="3" :sm="3" style="" class="app-layoutpanel-rowitem">
                    订单号：
                
                
                
                
                </ion-col>
                
                <ion-col v-show="detailsModel.order_no.visible"  :lg="4" :size="4" :sm="9" style="" class="app-layoutpanel-field no-padding">
                    <div class="item-field ">
                    
                    <app-mob-span  :context="context" :value="data.order_no" :itemParam="{}"  ></app-mob-span>
                </div>
                
                
                </ion-col>
                
                <ion-col v-show="detailsModel.create_time.visible"  :lg="5" :size="5" :sm="5" style="" class="app-layoutpanel-field no-padding">
                    <div class="item-field ">
                    
                    <app-mob-span  :context="context" :value="data.create_time" :itemParam="{}"  ></app-mob-span>
                </div>
                
                
                </ion-col>
                <ion-col v-show="detailsModel.container3.visible"  :size="12" style="height: 1px;" class="app-layoutpanel-container fgx">
                    <ion-row style="height:100%;">
                    </ion-row>
                </ion-col>
                <ion-col v-show="detailsModel.container4.visible"  :size="12" style="" class="app-layoutpanel-container">
                    <ion-row style="height:100%;">
                        <ion-col v-show="detailsModel.container6.visible"  :lg="4" :size="12" style="" class="app-layoutpanel-container">
                            <ion-row style="height:100%;">
                                
                                <ion-col v-show="detailsModel.cover_pic.visible"  :size="12" style="height: 90px;" class="app-layoutpanel-field">
                                    <div class="item-field ">
                                    
                                    <app-mob-picture 
                                    name='cover_pic' 
                                    style="overflow: auto;" 
                                    :multiple="false" 
                                    :data="JSON.stringify(this.data)" 
                                    :value="data.cover_pic" 
                                    :disabled="detailsModel.cover_pic.disabled" 
                                    :context="context" 
                                    :viewparams="viewparams"
                                    :readOnly="true"
                                    :uploadParam='{}' 
                                    :exportParam='{}'
                                    />
                                </div>
                                
                                
                                </ion-col>
                            </ion-row>
                        </ion-col>
                        <ion-col v-show="detailsModel.container7.visible"  :lg="8" :size="12" style="" class="app-layoutpanel-container">
                            <ion-row style="height:100%;">
                                
                                <ion-col v-show="detailsModel.goods_name.visible"  :lg="9" :size="9" :sm="9" style="" class="app-layoutpanel-field">
                                    <div class="item-field ">
                                    
                                    <app-mob-span  :context="context" :value="data.goods_name" :itemParam="{}"  ></app-mob-span>
                                </div>
                                
                                
                                </ion-col>
                                
                                <ion-col v-show="detailsModel.status.visible"  :lg="3" :size="3" :sm="3" style="" class="app-layoutpanel-field">
                                    <div class="item-field ">
                                    
                                    <app-mob-span  :context="context" :value="data.status" :itemParam="{}"   :isCache="false" codeListType="STATIC" :passwordFormat="{}" :enablepassword="false" tag="OrderStatus"></app-mob-span>
                                </div>
                                
                                
                                </ion-col>
                                
                                <ion-col v-show="detailsModel.price.visible"  :size="12" style="" class="app-layoutpanel-field">
                                    <div class="item-field ">
                                    
                                    <app-mob-span  :context="context" :value="data.price" :itemParam="{}"  ></app-mob-span>
                                </div>
                                
                                
                                </ion-col>
                            </ion-row>
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.goods_id.visible"  :size="12" style="" class="app-layoutpanel-field">
                            <div class="item-field ">
                            
                            <span class="app-form-hidden" style="display: none;">{{data.goods_id}}</span>
                        </div>
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.order_id.visible"  :size="12" style="" class="app-layoutpanel-field">
                            <div class="item-field ">
                            
                            <span class="app-form-hidden" style="display: none;">{{data.order_id}}</span>
                        </div>
                        
                        
                        </ion-col>
                    </ion-row>
                </ion-col>
                <ion-col v-show="detailsModel.container2.visible"  :size="12" style="height: 1px;" class="app-layoutpanel-container fgx">
                    <ion-row style="height:100%;">
                    </ion-row>
                </ion-col>
                <ion-col v-show="detailsModel.container5.visible"  :size="12" style="" class="app-layoutpanel-container">
                    <ion-row style="height:100%;">
                        
                        <ion-col v-show="detailsModel.rawitem2.visible"  :lg="3" :size="3" :sm="4" style="" class="app-layoutpanel-rowitem">
                            预约人：
                        
                        
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.order_contacts.visible"  :lg="3" :size="3" :sm="2" style="" class="app-layoutpanel-field">
                            <div class="item-field ">
                            
                            <app-mob-span  :context="context" :value="data.order_contacts" :itemParam="{}"  ></app-mob-span>
                        </div>
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.order_contacts_phone.visible"  :lg="3" :size="3" :sm="2" style="" class="app-layoutpanel-field">
                            <div class="item-field ">
                            
                            <app-mob-span  :context="context" :value="data.order_contacts_phone" :itemParam="{}"  ></app-mob-span>
                        </div>
                        
                        
                        </ion-col>
                        <ion-col v-show="detailsModel.button1.visible"  :lg="3" :size="3" :sm="3" style="" class="app-layoutpanel-button">
                            <app-mob-button  
                            
                            
                            
                            text="立即接单"
                            @click="button1_click($event)" />
                        
                        
                        </ion-col>
                        <ion-col v-show="detailsModel.button2.visible"  :lg="3" :size="3" :sm="3" style="" class="app-layoutpanel-button">
                            <app-mob-button  
                            
                            
                            
                            text="完成订单"
                            @click="button2_click($event)" />
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.rawitem3.visible"  :lg="3" :size="3" :sm="3" style="" class="app-layoutpanel-rowitem">
                            总人数：
                        
                        
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.people_num.visible"  :lg="6" :size="6" :sm="9" style="" class="app-layoutpanel-field">
                            <div class="item-field ">
                            
                            <app-mob-span  :context="context" :value="data.people_num" :itemParam="{}"  ></app-mob-span>
                        </div>
                        
                        
                        </ion-col>
                        <ion-col v-show="detailsModel.button3.visible"  :lg="3" :size="3" :sm="3" style="" class="app-layoutpanel-button">
                            <app-mob-button  
                            
                            
                            
                            text="订单详情"
                            @click="button3_click($event)" />
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.rawitem4.visible"  :lg="4" :size="4" :sm="4" style="" class="app-layoutpanel-rowitem">
                            预约时间：
                        
                        
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.order_start_time.visible"  :lg="4" :size="4" :sm="4" style="" class="app-layoutpanel-field">
                            <div class="item-field ">
                            
                            <app-mob-span  :context="context" :value="data.order_start_time" :itemParam="{}"  ></app-mob-span>
                        </div>
                        
                        
                        </ion-col>
                        
                        <ion-col v-show="detailsModel.order_end_time.visible"  :lg="4" :size="4" :sm="4" style="" class="app-layoutpanel-field">
                            <div class="item-field ">
                            
                            <app-mob-span  :context="context" :value="data.order_end_time" :itemParam="{}"  ></app-mob-span>
                        </div>
                        
                        
                        </ion-col>
                    </ion-row>
                </ion-col>
            </ion-row>
        </ion-col>
    </ion-row>
</div>
</template>
<script lang='ts'>
import { Vue, Component, Prop, Provide, Emit, Watch, Model } from 'vue-property-decorator';
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
import GlobalUiService from '@/global-ui-service/global-ui-service';
import Order_detailEntityService from '@/app-core/service/order-detail/order-detail-service';
import OrderDetailInfoService from '@/app-core/ctrl-service/order-detail/order-detail-info-panel-service';
import AppCenterService from "@/ibiz-core/app-service/app/app-center-service";

import Order_detailUIService from '@/ui-service/order-detail/order-detail-ui-action';

import { PanelUserControlModel, PanelButtonModel, PanelControlModel, PanelFieldModel, PanelRawitemModel, PanelContainerModel } from '@/model/panel-detail';


@Component({
    components: { }
})
export default class OrderDetailInfoBase extends Vue implements ControlInterface {

    /**
     * 名称
     *
     * @type {string}
     * @memberof OrderDetailInfo
     */
    @Prop() protected name?: string;

    /**
     * 视图名称
     *
     * @type {string}
     * @memberof OrderDetailInfo
     */
    @Prop() protected viewName!: string;


    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof OrderDetailInfo
     */
    @Prop() protected viewState!: Subject<ViewState>;

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof OrderDetailInfo
     */
    @Prop({ default: {} }) protected context?: any;

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof OrderDetailInfo
     */
    @Prop({ default: {} }) protected viewparams?: any;

    /**
     * 视图状态事件
     *
     * @protected
     * @type {(Subscription | undefined)}
     * @memberof OrderDetailInfo
     */
    protected viewStateEvent: Subscription | undefined;

    /**
     * 获取部件类型
     *
     * @returns {string}
     * @memberof OrderDetailInfo
     */
    protected getControlType(): string {
        return 'PANEL'
    }

    /**
     * 全局 ui 服务
     *
     * @type {GlobalUiService}
     * @memberof OrderDetailInfo
     */
    protected globaluiservice: GlobalUiService = new GlobalUiService();


    /**
     * 转化数据
     *
     * @param {any} args
     * @memberof  OrderDetailInfoBase
     */
    public transformData(args: any) {
        let _this: any = this;
        if(_this.service && _this.service.handleRequestData instanceof Function && _this.service.handleRequestData('transform',_this.context,args)){
            return _this.service.handleRequestData('transform',_this.context,args);
        }
    }

    /**
     * 建构部件服务对象
     *
     * @type {OrderDetailInfoService}
     * @memberof OrderDetailInfo
     */
    protected service: OrderDetailInfoService = new OrderDetailInfoService({$store:this.$store});

    /**
     * 实体服务对象
     *
     * @type {Order_detailService}
     * @memberof OrderDetailInfo
     */
    protected appEntityService: Order_detailEntityService = new Order_detailEntityService();

    /**
     * 界面UI服务对象
     *
     * @type {Order_detailUIService}
     * @memberof OrderDetailInfoBase
     */  
    public deUIService:Order_detailUIService = new Order_detailUIService(this.$store);
    

    /**
     * 逻辑事件
     *
     * @protected
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @returns {Promise<any>}
     * @memberof Mdctrl_itempanelBase
     */
    protected async mdctrl_itempanel_button1_click(params: any = {}, tag?: any, $event?: any): Promise<any> {

        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let contextJO: any = {};
        let paramJO: any = {};
        Object.assign(paramJO, {});
        xData = this;
        if (_this.getDatas && _this.getDatas instanceof Function) {
            datas = [..._this.getDatas()];
        }
        // 界面行为
        const curUIService: any = await this.globaluiservice.getService('order_detail_ui_action');
        if (curUIService) {
            curUIService.Order_detail_TaskOrderImm(datas, contextJO, paramJO, $event, xData, this);
        }
    }

    /**
     * 逻辑事件
     *
     * @protected
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @returns {Promise<any>}
     * @memberof Mdctrl_itempanelBase
     */
    protected async mdctrl_itempanel_button2_click(params: any = {}, tag?: any, $event?: any): Promise<any> {

        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let contextJO: any = {};
        let paramJO: any = {};
        Object.assign(paramJO, {});
        xData = this;
        if (_this.getDatas && _this.getDatas instanceof Function) {
            datas = [..._this.getDatas()];
        }
        // 界面行为
        const curUIService: any = await this.globaluiservice.getService('order_detail_ui_action');
        if (curUIService) {
            curUIService.Order_detail_CompleteOrder(datas, contextJO, paramJO, $event, xData, this);
        }
    }

    /**
     * 逻辑事件
     *
     * @protected
     * @param {*} [params={}]
     * @param {*} [tag]
     * @param {*} [$event]
     * @returns {Promise<any>}
     * @memberof Mdctrl_itempanelBase
     */
    protected async mdctrl_itempanel_button3_click(params: any = {}, tag?: any, $event?: any): Promise<any> {

        // 取数
        let datas: any[] = [];
        let xData: any = null;
        // _this 指向容器对象
        const _this: any = this;
        let contextJO: any = {};
        let paramJO: any = {};
        
        xData = this;
        if (_this.getDatas && _this.getDatas instanceof Function) {
            datas = [..._this.getDatas()];
        }
        // 界面行为
        const curUIService: any = await this.globaluiservice.getService('order_detail_ui_action');
        if (curUIService) {
            curUIService.Order_detail_OrderDetailInfo(datas, contextJO, paramJO, $event, xData, this);
        }
    }

    /**
     * 关闭视图
     *
     * @param {any[]} args
     * @memberof OrderDetailInfo
     */
    protected closeView(args: any[]): void {
        let _this: any = this;
        _this.$emit('closeview', args);
    }
    

   /**
     * 生命周期
     *
     *  @memberof OrderDetailInfo
     */  
    created(){
        this.afterCreated();
    }
   /**
     * 执行created后的逻辑
     *
     *  @memberof OrderDetailInfo
     */  
    afterCreated(){
        if(this.item){
            this.data = this.item;
            this.panelLogic({ name: '', newVal: null, oldVal: null });
            this.computeButtonState();
            return;
        }
       if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('load', action)) {
                    this.load(data);
                }
            });
        } 
        this.panelLogic({ name: '', newVal: null, oldVal: null });
    }
   /**
     * 数据
     *
     *  @memberof OrderDetailInfo
     */  
    public data :any ={} ;

    /**
     * 部件行为--fetch
     *
     * @type {string}
     * @memberof OrderDetailInfo
     */
    @Prop() protected fetchAction!: string;

   /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof Mob
     */
    @Prop({ default: true }) protected showBusyIndicator?: boolean;

    /**
     * 接口实现
     *
     * @returns {any[]}
     * @memberof OrderDetailInfo
     */
    getDatas(): any[] {
        if (!this.item) {
            return [];
        }
        return [this.item];
    }
    getData() {
        return this.item;
    }

    /**
     * 面板数据对象
     *
     * @type {*}
     * @memberof OrderDetailInfo
     */
    @Prop() protected item?: any;

	/**
	 * 面板 立即接单 事件
	 *
	 * @memberof @memberof OrderDetailInfo
	 */
    protected button1_click($event: any): void {
        this.mdctrl_itempanel_button1_click(null, null, $event);

    }
	/**
	 * 面板 完成订单 事件
	 *
	 * @memberof @memberof OrderDetailInfo
	 */
    protected button2_click($event: any): void {
        this.mdctrl_itempanel_button2_click(null, null, $event);

    }
	/**
	 * 面板 订单详情 事件
	 *
	 * @memberof @memberof OrderDetailInfo
	 */
    protected button3_click($event: any): void {
        this.mdctrl_itempanel_button3_click(null, null, $event);

    }

    /**
     * 数据加载
     *
     * @private
     * @param {*} [data={}]
     * @param {string} [type=""]
     * @returns {Promise<any>}
     * @memberof OrderDetailInfo
     */
    private async load(data: any = {}, type: string = ""): Promise<any> {
        const parentdata: any = {};
        this.$emit('beforeload', parentdata);
        Object.assign(data, parentdata);
        const response: any = await this.service.get(this.fetchAction, this.context, data, this.showBusyIndicator);
        if (!response || response.status !== 200) {
            this.$notify({ type: 'danger', message: response.info });
            return Promise.resolve(response);
        }
        this.$emit('load', (response.data && response.data.records) ? response.data.records : []);
        this.data = [];
        this.data = response.data.records;
        return Promise.resolve(response);
    }

    @Watch('item')
    public itemChange(){
         this.data = this.item;
    }


   /**
     * 表单逻辑
     *
     * @private
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof OrderDetailInfo
     */
    private panelLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
                



        if (Object.is(name, '') || Object.is(name, 'goods_id')) {
            let ret = false;
            const _goods_id = this.data.goods_id;
            if (this.$verify.testCond(this.data.goods_id, 'ISNOTNULL', '')) {
                ret = true;
            }
            this.detailsModel.container3.setVisible(ret);
        }









        if (Object.is(name, '') || Object.is(name, 'goods_id')) {
            let ret = false;
            const _goods_id = this.data.goods_id;
            if (this.$verify.testCond(this.data.goods_id, 'ISNOTNULL', '')) {
                ret = true;
            }
            this.detailsModel.container4.setVisible(ret);
        }















    }

   /**
     * 详情模型集合
     *
     * @type {*}
     * @memberof OrderDetailInfo
     */
    protected detailsModel: any = {
        rawitem1: new PanelRawitemModel({ caption: '', itemType: 'RAWITEM', name: 'rawitem1', panel: this, visible: true  })
, 
        order_no: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'order_no', panel: this, visible: true  })
, 
        create_time: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'create_time', panel: this, visible: true  })
, 
        container3: new PanelContainerModel({ caption: '', itemType: 'CONTAINER', name: 'container3', panel: this, visible: true  })
, 
        cover_pic: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'cover_pic', panel: this, visible: true  })
, 
        container6: new PanelContainerModel({ caption: '', itemType: 'CONTAINER', name: 'container6', panel: this, visible: true  })
, 
        goods_name: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'goods_name', panel: this, visible: true  })
, 
        status: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'status', panel: this, visible: true  })
, 
        price: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'price', panel: this, visible: true  })
, 
        container7: new PanelContainerModel({ caption: '', itemType: 'CONTAINER', name: 'container7', panel: this, visible: true  })
, 
        goods_id: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'goods_id', panel: this, visible: false  })
, 
        order_id: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'order_id', panel: this, visible: false  })
, 
        container4: new PanelContainerModel({ caption: '', itemType: 'CONTAINER', name: 'container4', panel: this, visible: true  })
, 
        container2: new PanelContainerModel({ caption: '', itemType: 'CONTAINER', name: 'container2', panel: this, visible: true  })
, 
        rawitem2: new PanelRawitemModel({ caption: '', itemType: 'RAWITEM', name: 'rawitem2', panel: this, visible: true  })
, 
        order_contacts: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'order_contacts', panel: this, visible: true  })
, 
        order_contacts_phone: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'order_contacts_phone', panel: this, visible: true  })
, 
        button1: new PanelButtonModel({ caption: '立即接单', itemType: 'BUTTON', name: 'button1', panel: this, visible: true , uiaction: { type: 'DEUIACTION', 
 tag: 'TaskOrderImm', actiontarget: 'SINGLEKEY',noprivdisplaymode:2,dataaccaction:'SRFUR__SHOP_COMM_BUT',visabled: true,disabled: false } })
, 
        button2: new PanelButtonModel({ caption: '完成订单', itemType: 'BUTTON', name: 'button2', panel: this, visible: true , uiaction: { type: 'DEUIACTION', 
 tag: 'CompleteOrder', actiontarget: 'SINGLEKEY',noprivdisplaymode:2,dataaccaction:'SRFUR__SHOP_COMP_BUT',visabled: true,disabled: false } })
, 
        rawitem3: new PanelRawitemModel({ caption: '', itemType: 'RAWITEM', name: 'rawitem3', panel: this, visible: true  })
, 
        people_num: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'people_num', panel: this, visible: true  })
, 
        button3: new PanelButtonModel({ caption: '订单详情', itemType: 'BUTTON', name: 'button3', panel: this, visible: true , uiaction: { type: 'DEUIACTION', 
 tag: 'OrderDetailInfo', actiontarget: 'SINGLEKEY',noprivdisplaymode:2,visabled: true,disabled: false } })
, 
        rawitem4: new PanelRawitemModel({ caption: '', itemType: 'RAWITEM', name: 'rawitem4', panel: this, visible: true  })
, 
        order_start_time: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'order_start_time', panel: this, visible: true  })
, 
        order_end_time: new PanelFieldModel({ caption: '', itemType: 'FIELD', name: 'order_end_time', panel: this, visible: true  })
, 
        container5: new PanelContainerModel({ caption: '', itemType: 'CONTAINER', name: 'container5', panel: this, visible: true  })
, 
        container1: new PanelContainerModel({ caption: '', itemType: 'CONTAINER', name: 'container1', panel: this, visible: true  })
, 
    };

    /**
     * 部件刷新
     *
     * @param {any[]} args
     * @memberof OrderDetailInfo
     */
    protected refresh(args: any[]): void {
        this.$emit('refresh',args);
    }

    /**
     * 计算面板按钮权限
     *
     * @param {any[]} args
     * @memberof OrderDetailInfo
     */
    protected computeButtonState() {
        const targetData = JSON.parse(JSON.stringify(this.data));
        if(this.detailsModel && Object.keys(this.detailsModel).length >0){
            Object.keys(this.detailsModel).forEach((name:any) =>{
                if(this.detailsModel[name] && this.detailsModel[name].uiaction && this.detailsModel[name].uiaction.dataaccaction && Object.is(this.detailsModel[name].itemType,"BUTTON")){
                    let tempUIAction:any = JSON.parse(JSON.stringify(this.detailsModel[name].uiaction));
                    this.$viewTool.calcActionItemAuthState(targetData,[tempUIAction], this.deUIService);
                    this.detailsModel[name].visible = tempUIAction.visabled;
                    this.detailsModel[name].disabled = tempUIAction.disabled;
                }
            })
        }
    }

}
</script>

<style lang='less'>
@import './order-detail-info-panel.less';
</style>

